home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / old / aegis.c next >
Encoding:
C/C++ Source or Header  |  1993-03-16  |  7.2 KB  |  319 lines

  1. /* $Id: aegis.c,v 1.1 1993/03/15 21:30:43 mjl Exp $
  2.    $Log: aegis.c,v $
  3.  * Revision 1.1  1993/03/15  21:30:43  mjl
  4.  * Files shuffled around in the Amiga driver reorganization.
  5.  *
  6.  * Revision 1.2  1992/10/12  17:11:17  mjl
  7.  * Amiga-specific mods, including ANSI-fication.
  8.  *
  9.  * Revision 1.1  1992/05/20  21:35:20  furnish
  10.  * Initial checkin of the whole PLPLOT project.
  11.  *
  12. */
  13.  
  14. /*    aegis.c
  15.  
  16.     PLPLOT Amiga Aegis draw format device driver.
  17. */
  18.  
  19. #include "plplot.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "dispatch.h"
  23. #include "plamiga.h"
  24.  
  25. /* Function prototypes */
  26.  
  27. static void flushbuffer (PLStream *);
  28.  
  29. /* top level declarations */
  30.  
  31. #define AEGX       10000
  32. #define AEGY       10000
  33. #define BSIZE  25
  34.  
  35. static short *buffptr, bufflen;
  36. static PLINT firstline;
  37. static short count, xmin, xmax, ymin, ymax;
  38.  
  39. /* (dev) will get passed in eventually, so this looks weird right now */
  40.  
  41. static PLDev device;
  42. static PLDev (*dev) = &device;
  43.  
  44. /*----------------------------------------------------------------------*\
  45. * aegis_init()
  46. *
  47. * Initialize device.
  48. \*----------------------------------------------------------------------*/
  49.  
  50. void 
  51. aegis_init(PLStream *pls)
  52. {
  53.     pls->termin = 0;        /* not an interactive terminal */
  54.     pls->icol = 1;
  55.     pls->width = 1;
  56.     pls->bytecnt = 0;
  57.     pls->page = 0;
  58.  
  59. /* Set up device parameters */
  60.  
  61.     dev->xold = UNDEFINED;
  62.     dev->yold = UNDEFINED;
  63.     dev->xmin = 0;
  64.     dev->xmax = AEGX;
  65.     dev->ymin = 0;
  66.     dev->ymax = AEGY;
  67.  
  68.     setpxl((PLFLT) 39.37, (PLFLT) 39.37);
  69.  
  70.     setphy(0, AEGX, 0, AEGY);
  71.  
  72.     bufflen = 2 * BSIZE;
  73.     buffptr = (short *) malloc(sizeof(short) * bufflen);
  74.     if (buffptr == NULL)
  75.     plexit("Out of memory!");
  76. }
  77.  
  78. /*----------------------------------------------------------------------*\
  79. * aegis_line()
  80. *
  81. * Draw a line in the current color from (x1,y1) to (x2,y2).
  82. \*----------------------------------------------------------------------*/
  83.  
  84. void 
  85. aegis_line(PLStream *pls, PLSHORT x1a, PLSHORT y1a, PLSHORT x2a, PLSHORT y2a)
  86. {
  87.     int x1=x1a, y1=y1a, x2=x2a, y2=y2a;
  88.     short *tempptr;
  89.  
  90.     if (pls->pscale)
  91.     plSclPhy(pls, dev, &x1, &y1, &x2, &y2);
  92.  
  93.     /* If starting point of this line is the same as the ending point of */
  94.     /* the previous line then don't raise the pen. (This really speeds up */
  95.     /* plotting and reduces the size of the file. */
  96.  
  97.     if (firstline) {
  98.     count = 0;
  99.     *(buffptr + count++) = x1;
  100.     *(buffptr + count++) = y1;
  101.     *(buffptr + count++) = x2;
  102.     *(buffptr + count++) = y2;
  103.     xmin = MIN(x1, x2);
  104.     ymin = MIN(y1, y2);
  105.     xmax = MAX(x1, x2);
  106.     ymax = MAX(y1, y2);
  107.     firstline = 0;
  108.     }
  109.     else if (x1 == dev->xold && y1 == dev->yold) {
  110.     if (count + 2 >= bufflen) {
  111.         bufflen += 2 * BSIZE;
  112.         tempptr = (short *) realloc((void *) buffptr, bufflen * sizeof(short));
  113.         if (tempptr == NULL) {
  114.         free((void *) buffptr);
  115.         plexit("Out of memory!");
  116.         }
  117.         buffptr = tempptr;
  118.     }
  119.     *(buffptr + count++) = x2;
  120.     *(buffptr + count++) = y2;
  121.     xmin = MIN(x2, xmin);
  122.     ymin = MIN(y2, ymin);
  123.     xmax = MAX(x2, xmax);
  124.     ymax = MAX(y2, ymax);
  125.     }
  126.     else {
  127.     flushbuffer(pls);
  128.     *(buffptr + count++) = x1;
  129.     *(buffptr + count++) = y1;
  130.     *(buffptr + count++) = x2;
  131.     *(buffptr + count++) = y2;
  132.     xmin = MIN(x1, x2);
  133.     ymin = MIN(y1, y2);
  134.     xmax = MAX(x1, x2);
  135.     ymax = MAX(y1, y2);
  136.     }
  137.  
  138.     dev->xold = x2;
  139.     dev->yold = y2;
  140. }
  141.  
  142. /*----------------------------------------------------------------------*\
  143. * aegis_polyline()
  144. *
  145. * Draw a polyline in the current color.
  146. \*----------------------------------------------------------------------*/
  147.  
  148. void 
  149. aegis_polyline (PLStream *pls, PLSHORT *xa, PLSHORT *ya, PLINT npts)
  150. {
  151.     PLINT i;
  152.  
  153.     for (i=0; i<npts-1; i++) 
  154.       aegis_line( pls, xa[i], ya[i], xa[i+1], ya[i+1] );
  155. }
  156.  
  157. /*----------------------------------------------------------------------*\
  158. * aegis_clear()
  159. *
  160. * Clear page.  
  161. * Here need to close file since only 1 page/file is allowed.
  162. \*----------------------------------------------------------------------*/
  163.  
  164. void 
  165. aegis_clear(PLStream *pls)
  166. {
  167.     /* Close the file */
  168.     if (!firstline) {
  169.     flushbuffer(pls);
  170.     }
  171.     fclose(pls->OutFile);
  172. }
  173.  
  174. /*----------------------------------------------------------------------*\
  175. * aegis_page()
  176. *
  177. * Set up for the next page.  
  178. * Advance to next family file if necessary (file output).
  179. * Here need to open a new file since only 1 page/file is allowed.
  180. \*----------------------------------------------------------------------*/
  181.  
  182. void 
  183. aegis_page(PLStream *pls)
  184. {
  185.     plOpenFile(pls);
  186.  
  187.     firstline = 1;
  188.     dev->xold = UNDEFINED;
  189.     dev->yold = UNDEFINED;
  190.     pls->page++;
  191.  
  192.     /* Write out header */
  193.     fprintf(pls->OutFile, "81086 0.0 0.0 100.0 100.0 0 10.\n");
  194.     fprintf(pls->OutFile, "\"%s\"\n-1\n", pls->FileName);
  195. }
  196.  
  197. /*----------------------------------------------------------------------*\
  198. * aegis_adv()
  199. *
  200. * Advance to the next page.
  201. \*----------------------------------------------------------------------*/
  202.  
  203. void 
  204. aegis_adv(PLStream *pls)
  205. {
  206.     aegis_clear(pls);
  207.     aegis_page(pls);
  208. }
  209.  
  210. /*----------------------------------------------------------------------*\
  211. * aegis_tidy()
  212. *
  213. * Close graphics file or otherwise clean up.
  214. \*----------------------------------------------------------------------*/
  215.  
  216. void 
  217. aegis_tidy(PLStream *pls)
  218. {
  219.     flushbuffer(pls);
  220.     free((VOID *) buffptr);
  221.     fclose(pls->OutFile);
  222.     pls->page = 0;
  223.     pls->OutFile = NULL;
  224. }
  225.  
  226.  
  227. /*----------------------------------------------------------------------*\
  228. * aegis_color()
  229. *
  230. * Set pen color.
  231. \*----------------------------------------------------------------------*/
  232.  
  233. void 
  234. aegis_color(PLStream *pls)
  235. {
  236.     flushbuffer(pls);
  237.     firstline = 1;
  238.  
  239.     /* Aegis pen 1 is the "paper" color */
  240.  
  241.     if (pls->icol < 2 || pls->icol > 15)
  242.     pls->icol = 0;
  243. }
  244.  
  245. /*----------------------------------------------------------------------*\
  246. * aegis_text()
  247. *
  248. * Switch to text mode.
  249. \*----------------------------------------------------------------------*/
  250.  
  251. void 
  252. aegis_text(PLStream *pls)
  253. {
  254. }
  255.  
  256. /*----------------------------------------------------------------------*\
  257. * aegis_graph()
  258. *
  259. * Switch to graphics mode.
  260. \*----------------------------------------------------------------------*/
  261.  
  262. void 
  263. aegis_graph(pls)
  264. PLStream *pls;
  265. {
  266. }
  267.  
  268. /*----------------------------------------------------------------------*\
  269. * aegis_width()
  270. *
  271. * Set pen width.
  272. \*----------------------------------------------------------------------*/
  273.  
  274. void 
  275. aegis_width(PLStream *pls)
  276. {
  277.     flushbuffer(pls);
  278.     firstline = 1;
  279.  
  280.     if (pls->width < 1)
  281.     pls->width = 1;
  282.     else if (pls->width > 4)
  283.     pls->width = 4;
  284. }
  285.  
  286. /*----------------------------------------------------------------------*\
  287. * aegis_esc()
  288. *
  289. * Escape function.
  290. \*----------------------------------------------------------------------*/
  291.  
  292. void 
  293. aegis_esc(PLStream *pls, PLINT op, char *ptr)
  294. {
  295. }
  296.  
  297. /*----------------------------------------------------------------------*\
  298. * flushbuffer()
  299. *
  300. * Spit out buffer to file.
  301. \*----------------------------------------------------------------------*/
  302.  
  303. static void 
  304. flushbuffer(PLStream *pls)
  305. {
  306.     short i = 0;
  307.  
  308.     fprintf(pls->OutFile, "1 52 %.2f %.2f", xmin / 100., ymin / 100.);
  309.     fprintf(pls->OutFile, " %.2f %.2f", xmax / 100., ymax / 100.);
  310.     fprintf(pls->OutFile, " %d 0 0 %d 0\n", pls->icol, pls->width-1);
  311.     while (i < count) {
  312.     fprintf(pls->OutFile, " 1 %.2f %.2f\n",
  313.         *(buffptr + i) / 100., *(buffptr + i + 1) / 100.);
  314.     i += 2;
  315.     }
  316.     fprintf(pls->OutFile, " 0\n");
  317.     count = 0;
  318. }
  319.